import pandas  as pddf = pd.read_excel('2018、19已报到未报到学生基本情况.xls')df['省'] = Nonedf['市'] = Nonefor i in df.index:    info = str(df.loc[i,'生源地']).split('省')    pri = info[0]    df.loc[i,'省'] = pri.split('市')[0]    if '区' in str(df.loc[i, '省']):        df.loc[i, '省']  = str(df.loc[i, '省']).split('区')[0]+'区'    try:        city = info[1]        df.loc[i, '市'] = city.split('市')[0]    except IndexError:        city = info[0]        df.loc[i, '市'] = city    print(i)df.to_csv('2018、19已报到未报到学生基本情况(02).csv',index=False,na_rep=" ")# df = pd.read_excel('2018、19已报到未报到学生基本情况(3).xls')# for i in df.index:#    if '区' in str(df.loc[i, '省']):#         print(df.loc[i, '省'])#         df.loc[i, '省']  = str(df.loc[i, '省']).split('区')[0]+'区'#         print(i)# df.to_excel('2018、19已报到未报到学生基本情况(4).xls',index=False)